import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:family_app/src/theme/app_theme.dart';

/// 资产卡片组件
/// 显示总资产、本月收入、本月支出的概览卡片
class AssetCard extends StatelessWidget {
  /// 总资产金额
  final double totalAmount;

  /// 本月收入
  final double monthIncome;

  /// 本月支出
  final double monthExpense;

  const AssetCard({
    Key? key,
    required this.totalAmount,
    required this.monthIncome,
    required this.monthExpense,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: [
            AppTheme.primaryColor,
            AppTheme.primaryColor.withOpacity(0.7),
          ],
        ),
        borderRadius: BorderRadius.circular(20.r),
        boxShadow: [
          BoxShadow(
            color: AppTheme.primaryColor.withOpacity(0.3),
            blurRadius: 10,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      padding: EdgeInsets.all(8.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 总资产标题
          Text(
            '总资产',
            style: TextStyle(
              fontSize: 8.sp,
              color: Colors.white.withOpacity(0.8),
              fontWeight: FontWeight.w500,
            ),
          ),
          SizedBox(height: 4.h),

          // 总资产金额
          Text(
            '¥ ${totalAmount.toStringAsFixed(2)}',
            style: TextStyle(
              fontSize: 14.sp,
              fontWeight: FontWeight.w300,
              color: Colors.white,
            ),
          ),
          SizedBox(height: 4.h),

          // 分割线
          Divider(
            color: Colors.white.withOpacity(0.2),
            height: 1,
          ),
          SizedBox(height: 4.h),

          // 收入和支出统计
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              _buildSummaryItem(
                context,
                '本月收入',
                '+¥ ${monthIncome.toStringAsFixed(0)}',
                Colors.green,
              ),
              _buildSummaryItem(
                context,
                '本月支出',
                '-¥ ${monthExpense.toStringAsFixed(0)}',
                Colors.red,
              ),
            ],
          ),
        ],
      ),
    );
  }

  /// 构建统计项目
  Widget _buildSummaryItem(
    BuildContext context,
    String label,
    String value,
    Color color,
  ) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          label,
          style: TextStyle(
            fontSize: 8.sp,
            color: Colors.white.withOpacity(0.8),
            fontWeight: FontWeight.w500,
          ),
        ),
        SizedBox(height: 4.h),
        Text(
          value,
          style: TextStyle(
            fontSize: 10.sp,
            fontWeight: FontWeight.w600,
            color: color,
          ),
        ),
      ],
    );
  }
}
